package com.lcz.demo.customerorder;

import com.lcz.demo.exception.ApiRequestException;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RequestMapping(path="api/v2/customers")
@RestController
//控制器
public class CustomerControllerV2 {
private final CustomerService customerService;

    public CustomerControllerV2(CustomerService customerService) {
        this.customerService = customerService;
    }
@GetMapping
     List <Customer> getCustomers(){
        return customerService.getCustomers();
}

@GetMapping(path={"{customerId}"})
Customer getcustomer(@PathVariable("customerId")Long id){
        return customerService.getcustomer(id);
}
@GetMapping(path = {"{customerId}/exception"})
    Customer getException(@PathVariable("customerId") Long id){
        throw  new ApiRequestException("ApiRequestException for customer"+id);


}
@Valid
@PostMapping
    void createCustomer(@RequestBody Customer customer){
    System.out.println("POST 请求..");
    System.out.println(customer);
}
@PutMapping
    void updateCustomer(@RequestBody Customer customer){
    System.out.println("UNPDATE ...");
    System.out.println(customer);
}
@DeleteMapping(path = {"{customerId}"})
    void deleteCustomer(@PathVariable("customerId") Long id){
    System.out.println("DELETE 请求 删除customer 其ID"+id);
}


}
